\chapter{Program structure}
We decided to implement the program as a state machine where most of the states are represented by their own classes and threads. The state machine class (\textit{SM}) is the overviewing instance of the whole process. Once started the \textit{SM} starts external threads to run particial tasks, e.g. the procedure to adjust the beam (\textit{Beam}), and  decides when a running thread should be stopped.

\begin{figure}[htb]
\begin{center}
\ifpdf
	\includegraphics[scale=1.0]{img/Klassendiagramm.jpg}
\else
%	\includegraphics[scale=0.8]{img/Klassendiagramm.jpg}
\fi
\caption{UML-diagram}
\label{fig:uml}
\end{center}
\end{figure}

The main class is the starting procedure of the catch and throw process. All active instances of the programm are to be called from the \textit{StateMachine} class or the \textit{Opcom} class.

\section{Main class}
This class creates an instance of the Opcom and the State Machine class, exchanges references (connects them) and starts both. It is the entering point to start the program.

\section{Opcom class}
The Opcom class contains the graphical user interfase (GUI) for the process (see also \ref{user_interface}). It contains graphs of the current beam angle, the current beam reference, the current ball position, the current ball position reference and the controller output. Through a tabbed panel the user can tune all parameters \textit{DoubleFields} of the different particial tasks. The main tab holds a \textit{Radiobutton} to switch the state machine mode form \textbf{auto} to \textbf{step}. In \textbf{step} mode an extra condition is added to the transitions of the \textit{SM}. To fulfill this condition the user must click onto a \textit{step button} and so agree manually. This mode should be used for debugging and tuning purposes. To avoid synchronizing problems, all parameter changes must be done while the \textit{SM} is in intial conditions. Otherwise the required tabs will be disabled and not reachable for the user.

\section{StateMachine class}
This class implements a state machine as tought in the lecture. It creates instances of the "state-classes" Beam, BallAndBeam and Throw and starts or stops them. It creates also the references needed for the controllers. The state machine can be run in either auto- or in step-mode. 

\section{Beam class}
With the help of a PI-Controller this class positions the Beam. The reference and the check if the final position is reached is done in the state machine. An additional method (\textit{public boolean hasreached(double $y$, double $y_{Ref}$, double $epsilon$)}) returns \textbf{true} if $y$ is located in an $epsilon$ area around $y_{Ref}$. This method and the signal from the light sensor can be used to determine if the final position is reached.

\section{BeamAndBall class}
The BeamAndBall class uses the same priciples as int the laboratory to control the ball on the beam. The control will be a cascaded PI and PID control. The control should be robust enough to handle all diffent kinds of balls.\\
It also contains a method to estimate the size of the ball, depending on the control effort while traveling the ball. The reference generation is also done by the state machine. 

\section{Throw class}
The Throw class implements the throwing (or dropping) process of the ball depending on the size.
